package com.yjy.fuyao.vod.api;

import com.aliyun.vod.upload.resp.UploadStreamResponse;
import com.yjy.fuyao.utils.result.R;
import com.yjy.fuyao.vod.service.VodService;
import com.yjy.fuyao.vod.util.VodProperties;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Api(tags = "视频管理")
@RestController
@RequestMapping("/api/vod")
public class VodController {

    @Resource
    private VodService vodService;

    @ApiOperation(value = "删除视频")
    @DeleteMapping("/remove")
    public R removeById(
            @ApiParam(name = "视频Id",value = "1",required = true)
            @RequestParam("id") String id){
        vodService.vodDeleteVideo(VodProperties.KEY_ID,VodProperties.KEY_SECRET,id);
        return R.ok();
    }

    @ApiOperation(value = "上传视频")
    @PostMapping("/upload")
    public R uploadVideo(
            @ApiParam(value = "文件", required = true)
            @RequestParam("file") MultipartFile file){
        UploadStreamResponse response = vodService.uploadVideo(file);
        System.out.println("response:==============================="+response.getVideoId());
        return R.ok().data("videoId",response.getVideoId());
    }
}
